package com.xjtu.platform.user.admin.time_set.imply;

import com.xjtu.platform.common.Utils;
import com.xjtu.platform.user.admin.time_set.TimeSetDto;
import com.xjtu.platform.user.admin.time_set.TimeSetService;
import com.xjtu.platform.user.admin.time_set.dao.TimeSetDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

@Service
@Transactional
public class TimeSetImply implements TimeSetService {
    @Resource
    TimeSetDao timeSetDao;



    @Override
    public boolean timeAdd(TimeSetDto dto) {

        if(timeSetDao.countTime()>=4){
            return false;
        }
        int count = timeSetDao.countTime()+1;
        dto.setTime_id(count+"");
        timeSetDao.timeAdd(dto);
        return true;
    }



    @Override
    public Map<String, Object> getInfo(TimeSetDto dto) {
        return Utils.getPage(dto,()->timeSetDao.getInfo(dto));
    }

    @Override
    public boolean changeTime(TimeSetDto dto) {
        timeSetDao.changeTime(dto);
        return true;
    }


    @Override
    public void clearTime(){
        timeSetDao.clearTime();
    }

    @Override
    public boolean checkTime(TimeSetDto dto){
        if(Integer.parseInt(dto.getStart_time().substring(0,1))>Integer.parseInt(dto.getEnd_time().substring(0,1))){
            return false;
        }
        int ok = timeSetDao.checkTime(dto);
        return ok==0;
    }
}
